<?php

class UserIdentity extends CUserIdentity{
    
    protected $_id;
    private $USER;
    
    function __construct(){
        parent::__construct('', '');
    }
    
    public function auth($type, $params, $authCondition=true){
        
        $this->USER = Users::model()->findByAttributes(array(
            'email' => $params['email'],
            'password' => md5(PASSWORD_SECRET1.$params['password'].PASSWORD_SECRET2),
            'active' => 1,
        ));
        
        if(!$this->USER or !$authCondition) {
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        } else {
            $this->_id = $this->USER->id;
            $this->username = '['.$this->USER->nick.'] '.$this->USER->name.' '.$this->USER->lname;
            $this->errorCode = self::ERROR_NONE;
        }
        
        return !$this->errorCode;
        
    }
    
    public function getId(){
        return $this->_id;
    }
    
    public function getModel(){
        return $this->USER;
    }
}
